package com.ruoyi.project.hcy.administrations.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hcy.administrations.domain.Approve;
import com.ruoyi.project.hcy.administrations.service.IApproveService;
import com.ruoyi.project.hcy.administrations.util.ApproveAgreeUtil;
import com.ruoyi.project.hcy.administrations.util.ApproveDisAgreeUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ApproveController
 * @Author 金刚芭比
 * @Date 2020/9/17 10:55
 * @Version 1.0
 */
@Controller
@RequestMapping("/hcy/approve")
public class ApproveController extends BaseController {

    private String prefix = "hcy/administrations";

    @Autowired
    private IApproveService approveService;

    //封装的方法
    @Autowired
    private ApproveDisAgreeUtil approvePassUtil;
    @Autowired
    private ApproveAgreeUtil approveAgreeUtil;

    @GetMapping
    public String toApprove() {
        return prefix + "/approve";
    }

    @ResponseBody
    @RequiresPermissions("hcy:approve:list")
    @PostMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<Approve> list = approveService.selectApproveList("待审批..");
        return getDataTable(list);
    }

    @ResponseBody
    @PostMapping("/remove")
    @RequiresPermissions("hcy:approve:remove")
    public AjaxResult disAgree(Integer ids){

        return toAjax(approvePassUtil.DisAgreeUtil(ids));
    }

    @RequiresPermissions("hcy:approve:edit")
    @RequestMapping("/agree")
    public String Agree(Integer approvId){
        System.out.println(11111);
        System.out.println(approvId);
        approveAgreeUtil.Agree(approvId);
        return prefix + "/approve";
    }
}
